"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const LoggerWriter_1 = require("./LoggerWriter");
const defaults = require("lodash.defaults");
class ConsoleLoggerWriter extends LoggerWriter_1.DefaultLoggerWriter {
    constructor(name, options = {}) {
        options = defaults(options, {
            timeFormat: 'HH:mm:ss.SSS',
        });
        super(name, options);
    }
    write(methodName, timestamp, ...msg) {
        const prefix = this.format(methodName, timestamp);
        const [first] = msg;
        if (typeof first === 'string') {
            msg[0] = prefix + ' ' + first;
        }
        else {
            msg.unshift(prefix);
        }
        let consoleMethod;
        if (methodName === 'trace' || methodName === 'debug') {
            consoleMethod = console.log;
        }
        else {
            consoleMethod = console[methodName];
        }
        if (methodName === 'trace') {
            msg.push(`\n${this.getTraceStack()}`);
        }
        consoleMethod.apply(console, msg);
    }
    formatTime(timestamp) {
        return chalk_1.default.grey(`[${super.formatTime(timestamp)}]`);
    }
    formatLevel(methodName) {
        return ConsoleLoggerWriter.styles[super.formatLevel(methodName)];
    }
    formatName(loggerName) {
        return chalk_1.default.green(super.formatName(loggerName));
    }
}
exports.ConsoleLoggerWriter = ConsoleLoggerWriter;
ConsoleLoggerWriter.styles = {
    TRACE: chalk_1.default.cyan('trace'),
    DEBUG: chalk_1.default.magenta('verb'),
    INFO: chalk_1.default.blue('info'),
    WARN: chalk_1.default.yellow('WARN'),
    ERROR: chalk_1.default.red('ERR!'),
};
